from conans import ConanFile, CMake, tools
from conans import tools
import os
import sys
class YamlCppConan(ConanFile):
    name = "yaml-cpp"
    version = "0.6.0"
    url = "https://gitee.com/mirrors/yaml-cpp.git"
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False]}
    default_options = {"shared": False}
    generators = "cmake"
    
    def source(self):
        tools.rmdir("pkgsrc")
        git = tools.Git(folder=self.source_folder + "/pkgsrc", verify_ssl=False)
        git.clone("https://gitee.com/mirrors/yaml-cpp.git")

    def build(self):
        cmake = CMake(self)
        print("path " + self.source_folder + " is where the package built")
        print("build env is ",tools.get_env("BUILD_ENV"))
        tools.rmdir(tools.unix_path(self.package_folder)+"/build")
        tools.mkdir(tools.unix_path(self.package_folder)+"/build")
        if tools.os_info.is_windows:
            print("current os windows")
            if tools.os_info.is_cygwin:
                print("cygwin build")
            if tools.get_env("BUILD_ENV")=="msys":
                print("msys build")
                tools.run_in_windows_bash(self, subsystem="msys", cwd="pkgsrc", bashcmd="cmake build -DCMAKE_MODULE_PATH=" + tools.unix_path(self.source_folder)
                                          + " -G\"MinGW Makefiles\" " + tools.unix_path(self.source_folder) + "//pkgsrc")
                tools.run_in_windows_bash(
                    self, subsystem="msys", cwd="pkgsrc", bashcmd="cmake --build .")

    def package(self):
        self.copy("*.h", dst="include", src="pkgsrc/include",keep_path=True)
        self.copy("*.hpp", dst="include", src="pkgsrc/include",keep_path=True)
        self.copy("*.a", dst="lib", src="pkgsrc",keep_path=True)

    def package_info(self):
        self.cpp_info.libs = ["hello"]

